<?php
@session_start();
require_once("../includes/public.inc.php");
$s = isset($_GET['s'])?$_GET['s']:'';
$act = isset($_GET['act'])?$_GET['act']:'user';//也是type
$openid = isset($_GET['openid'])?$_GET['openid']:'';//echo $openid;exit;
if ($act=='user')
{
	$user = isset($_POST['user'])?$_POST['user']:'';//手机号
	$username = isset($_POST['userName'])?$_POST['userName']:'';//真实姓名
	$sex = isset($_POST['rdoSex'])?$_POST['rdoSex']:'';
	$province = isset($_POST['province'])?str_replace( mb_substr(trim($_POST['province']), -1,1,'UTF-8'),'',trim($_POST['province'])):'';
	//echo $province;exit;
	$city = isset($_POST['city'])?str_replace( mb_substr(trim($_POST['city']), -1,1,'UTF-8'),'',trim($_POST['city'])):'';
	$district = isset($_POST['district'])?$_POST['district']:'';
	$street = isset($_POST['street'])?$_POST['street']:'';
	$address = isset($_POST['address'])?$_POST['address']:'';
	$qq = isset($_POST['qq'])?$_POST['qq']:'';
	$weixin = isset($_POST['weixin'])?$_POST['weixin']:'';
	if (!$address)
	{
		$address = isset($_POST['autoaddress'])?$_POST['autoaddress']:'';
	}
}
else 
{
	echo "<script>alert('注册失败!入口不正确');history.go(-1);</script>";exit;
}
if ($user&&$username&&$qq)
{
	//echo "select * from " .DBQIAN. "daogou where username='".trim($user)."' or openid='".$openid."'";exit;
	$select_dg = mysql_fetch_array(mysql_query("select * from " .DBQIAN. "users where username='".trim($user)."' or openid='".$openid."'"));
	if ($select_dg)
	{
		echo "<script>alert('注册失败!你已经注册，请直接登录.需要找回密码，请联系管理员!');history.go(-1);</script>";exit;
	}
	if ($act == 'user')
	{
		//echo "insert into ".DBQIAN."users(username,name,sex,province,city,address,last_login,createtime,openid,join) values('".$user."','".$username."','".$sex."','".$province."','".$city."','".$address."','".time()."','".date('Y-m-d H:i:s',time())."','".$openid."','".$join."')";exit;
		$add = mysql_query("insert into ".DBQIAN."users(username,name,sex,province,city,address,last_login,createtime,openid,qq,weixin) values('".$user."','".$username."','".$sex."','".$province."','".$city."','".$address."','".time()."','".date('Y-m-d H:i:s',time())."','".$openid."','".trim($qq)."','".trim($weixin)."')");
		$add_id = mysql_insert_id();//echo $add_id;exit;
		//print_r($add);exit;
		if ($add&&$add_id)
		{
			$exsit_user = mysql_fetch_array(mysql_query("select * from ".DBQIAN."users where id=".$add_id." order by id desc limit 1"));
			if ($exsit_user)
			{
				$_SESSION['username'] = $exsit_user['username'];
				header("Location: zhengpu.php?s=".trim($s)."&openid=".$openid);exit;//注册成功后直接跳到审核页面
			}
			else 
			{
				header("Location: loginu.php?s=".$s."&openid=".$openid);exit;//注册失败跳到登录页面
			}
		}
		else 
		{
			echo "<script>alert('注册失败!');history.go(-1);</script>";exit;
		}
	}
}
else 
{
	echo "<script>alert('请正确并完整填写你的信息!');history.go(-1);</script>";exit;
}